#!/usr/bin/python
#coding=utf-8
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey,Enum
from sqlalchemy.orm import mapper,relationship
from sqlalchemy.orm import sessionmaker
import db_init
import chardet
class Ray_Video_File(object):
	def __init__(self):
		self.Categories		="";
		self.Title     		=""
		self.Uri       		="";
		self.Tags		="";
		self.Description	="";
		self.Time		= 0;
		self.Date		="";
		self.Owner		="";
		self.Rate		=0.0;
		self.RateCount		=0
		self.CommentsCount	=0
		self.Featured		=0
		self.Status		="";
		self.Source		="";
		self.Video		="";
		
		return;
	def publish_video(self,category,title,uri,tag,des,date,owner,status):
		self.Categories 	= category;
		self.Title		= title;
		self.Uri		= uri;
		self.Tags		= tag;
		self.Description	= des;
		self.Date		= date;
		self.Owner		= owner
		self.Status		= status
		
class Ray_Video_Album(object):
	def __init__(self):
		self.Caption		="";
		self.Uri		="";
		self.Location		="";
		self.Description	="";
		self.Type		="bx_videos";
		self.Owner		=1;
		self.Status		="passive";
		self.Date		=0;
		self.ObjCount		=0;
		self.LastObjId		=0;
		"""
			1 default
			2 me only
			3 public 
			4 member
			5 friends
		"""

		self.AllowAlbumView	=3;
class Ray_Video_In_Album(object):
	pass
class Ray_Video_Category(object):
	pass
#map the object to table
mapper(Ray_Video_Category,db_init.video_category_table)
mapper(Ray_Video_File,db_init.ray_video_table);
mapper(Ray_Video_Album,db_init.video_albums_table);
mapper(Ray_Video_In_Album,db_init.video_in_albums_table, primary_key=[db_init.video_in_albums_table.c.id_album,db_init.video_in_albums_table.c.id_object,db_init.video_in_albums_table.c.obj_order]);



if __name__ == "__main__":
#create session
	Session 		= sessionmaker(bind=db_init.engine_publish)
	session			= Session();
	for row in session.query(Ray_Video_File).all():
		print row.ID ,row.Title
	for row in session.query(Ray_Video_In_Album).all():
		print row.id_album,row.id_object,row.obj_order
	print chardet.detect("你好")
	for row in session.query(Ray_Video_Category).all():
		print row.Category



